﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace Phoenix.Backend
{
    public partial class Login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnLogin_Click(object sender, EventArgs e)
        {
            DataTable dt = Phoenix.AppCode.Bussiness.UsersService.UsersLogin(txtUserName.Text, txtPass.Text);
            if (dt.Rows.Count > 0)
            {
                Session["UserName"] = dt.Rows[0]["UserName"].ToString();
                Session["ID_UserName"] = dt.Rows[0]["ID_Users"].ToString();
                Phoenix.AppCode.Bussiness.UsersService.UsersLastLogin(Session["ID_UserName"].ToString());
                if (chbRemember.Checked == true)
                {
                    HttpCookie Uid = new HttpCookie("Uid", txtUserName.Text);
                    Uid.Expires = DateTime.Now.AddDays(30);
                    Response.Cookies.Add(Uid);
                    HttpCookie Pwd = new HttpCookie("Pwd", txtPass.Text);
                    Pwd.Expires = DateTime.Now.AddDays(30);
                    Response.Cookies.Add(Pwd); 
                }
                Response.Redirect("ProfileInfo.aspx?ID="+Session["ID_UserName"].ToString()+"");
            }
            
            
        }
    }
}